/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package servlet;

import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.CommandRunner;


/**
 *
 * @author pyin
 */
@Singleton
public class TSRunnerStateServlet extends HttpServlet {
    private CommandRunner commandRunner;

    @Inject
    public TSRunnerStateServlet(CommandRunner commandRunner){
        this.commandRunner = commandRunner;
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        PrintWriter out = response.getWriter();
        String state = new Boolean(commandRunner.isRunning()).toString();
        if(state.equalsIgnoreCase("true")){
            out.print("<div class='success'>Running&nbsp;&nbsp;&nbsp;&nbsp;<a href='#' onClick='stopTSRunner()'>stop</a></div>");
        }else{
            out.print("<div class='error'>Stopped&nbsp;&nbsp;&nbsp;&nbsp;<a href='#' onClick='startTSRunner()'>start</a></div>");
        }
    }
}
